/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.feedback.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.component.feedback.result.FeedbackCreateResult;
import info.peigen.hotpot.component.feedback.result.FeedbackDeleteResult;
import info.peigen.hotpot.component.feedback.result.FeedbackEditResult;
import info.peigen.hotpot.component.feedback.service.order.FeedbackCreateOrder;
import info.peigen.hotpot.component.feedback.service.order.FeedbackDeleteOrder;
import info.peigen.hotpot.component.feedback.service.order.FeedbackEditOrder;
import info.peigen.hotpot.component.feedback.service.order.FeedbackOrder;
import info.peigen.hotpot.component.feedback.service.result.FeedbackResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(FeedbackService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/11/16
 */
@Component
public class FeedbackService extends AbstractFeedbackService {

    public FeedbackResult feedback(FeedbackOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new FeedbackResult()).build();

        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackActiveDomainProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackStoreProcessor);
            }
        });

        return (FeedbackResult) serviceContext.getResult();
    }

    public FeedbackCreateResult create(FeedbackCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new FeedbackCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackCreateResultProcessor, feedbackStoreProcessor);
            }
        });
        return (FeedbackCreateResult) serviceContext.getResult();
    }

    public FeedbackEditResult edit(FeedbackEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new FeedbackEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackActiveProcessor, feedbackEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackEditResultProcessor, feedbackStoreProcessor);
            }
        });
        return (FeedbackEditResult) serviceContext.getResult();
    }

    public FeedbackDeleteResult delete(FeedbackDeleteOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new FeedbackDeleteResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors();
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(feedbackDeleteProcessor, feedbackDeleteResultProcessor);
            }
        });
        return (FeedbackDeleteResult) serviceContext.getResult();
    }
}